package com.ytktt.study.week11.task10;

import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;

/**
 * 点击量计数
 *
 * @author ytk
 */
@Slf4j
public class HitsApplication {

    public static void main(String[] args) {
        RedisClient redisClient = RedisClient.create("redis://localhost:6379/0");
        StatefulRedisConnection<String, String> connection = redisClient.connect();
        RedisCommands<String, String> syncCommands = connection.sync();
        for (int i = 0; i < 100000; i++) {
            String userId = RandomStringUtils.random(10);
            syncCommands.pfadd("hot", userId);
        }
        log.info("hot hits count: {}", syncCommands.bitcount("hot"));
        connection.close();
        redisClient.shutdown();
    }
}
